package com.android.list;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;

import android.content.Context;

import android.widget.BaseAdapter;
import android.widget.TextView;

public class AddTailAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<String> data = new ArrayList<String>();
	
	public AddTailAdapter(Context context) { 
		data.add("Item: 1");
		data.add("Item: 2");
		data.add("Item: 3");
		data.add("Item: 4");
		mInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int item) {
		return item;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if (convertView == null) {
			convertView	= mInflater.inflate(R.layout.item, null);
			
			holder 		= new ViewHolder();
			
			holder.mTitleText	= (TextView) convertView.findViewById(R.id.txtItem);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.mTitleText.setText(data.get(position));
		
		return convertView;
	}

	static class ViewHolder {
		TextView mTitleText;
	}
    public void addTail() {
        //Add 3 item vào đuôi
        for(int i=0;i<5;i++){
        	data.add("Item: "+(data.size()+1));
        }
        notifyDataSetChanged();
    }
}